home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / util / misc / VMM_src.lha / VMM / MUI / mui.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-16  |  15.0 KB  |  522 lines

  1. #include "defs.h"
  2.  
  3. char *Pages [4];
  4.  
  5. static struct NewMenu Menu [] = {
  6.   { NM_TITLE, NULL,        0, 0, 0, (APTR) 0          },
  7.   { NM_ITEM,  NULL,        0, 0, 0, (APTR) OPEN_ID    },
  8.   { NM_ITEM,  NULL,        0, 0, 0, (APTR) SAVE_AS_ID },
  9.   { NM_ITEM,  NULL,        0, 0, 0, (APTR) SAVE_WIN_ID },
  10.   { NM_ITEM,  NM_BARLABEL, 0, 0, 0, (APTR) 0          },
  11.   { NM_ITEM,  NULL,        0, 0, 0, (APTR) ABOUT_ID   },
  12.   { NM_ITEM,  NM_BARLABEL, 0, 0, 0, (APTR) 0          },
  13.   { NM_ITEM,  NULL,        0, 0, 0, (APTR) HIDE_ID    },
  14.   { NM_ITEM,  NULL,        0, 0, 0, (APTR) MUIV_Application_ReturnID_Quit },
  15.  
  16.   { NM_TITLE, NULL,        0, 0, 0, (APTR) 0             },
  17.   { NM_ITEM,  NULL,        0, 0, 0, (APTR) RESET_ID      },
  18.   { NM_ITEM,  NULL,        0, 0, 0, (APTR) LAST_SAVED_ID },
  19.   { NM_ITEM,  NULL,        0, 0, 0, (APTR) RESTORE_ID    },
  20.   { NM_END,   0,           0, 0, 0, (APTR) 0             }
  21. };
  22.  
  23. /***********************************************************************/
  24.  
  25. static void AttachID_BT (Object *obj, ULONG id)
  26.  
  27. {
  28. DoMethod (obj, MUIM_Notify,
  29.           MUIA_Pressed, FALSE,
  30.           Application,
  31.           2,
  32.           MUIM_Application_ReturnID, id);
  33. }
  34.  
  35. /***********************************************************************/
  36.  
  37. static void AttachID_CY (Object *obj, ULONG id)
  38.  
  39. {
  40. DoMethod (obj, MUIM_Notify,
  41.           MUIA_Cycle_Active, MUIV_EveryTime,
  42.           Application,
  43.           2,
  44.           MUIM_Application_ReturnID, id);
  45. }
  46.  
  47. /***********************************************************************/
  48.  
  49. static void AttachID_ST (Object *obj, ULONG id)
  50.  
  51. {
  52. DoMethod (obj, MUIM_Notify,
  53.           MUIA_String_Acknowledge, MUIV_EveryTime,
  54.           Application,
  55.           2,
  56.           MUIM_Application_ReturnID, id);
  57. }
  58.  
  59. /***********************************************************************/
  60.  
  61. BOOL CreateGUI (void)
  62.  
  63. {
  64. /* creates the GUI, opens the window and returns an application object */
  65. Pages [0] = GetVMMString (msgTasksProgs);
  66. Pages [1] = GetVMMString (msgMemory);
  67. Pages [2] = GetVMMString (msgMisc);
  68. Pages [3] = NULL;
  69.  
  70. Menu [0].nm_Label   = GetVMMString (msgProject);
  71. Menu [1].nm_Label   = GetVMMString (msgOpen);
  72. Menu [1].nm_CommKey = GetVMMString (msgOpenShort);
  73. Menu [2].nm_Label   = GetVMMString (msgSaveAs);
  74. Menu [2].nm_CommKey = GetVMMString (msgSaveAsShort);
  75. Menu [3].nm_Label   = GetVMMString (msgSaveWindow);
  76. Menu [5].nm_Label   = GetVMMString (msgAbout);
  77. Menu [7].nm_Label   = GetVMMString (msgHide);
  78. Menu [7].nm_CommKey = GetVMMString (msgHideShort);
  79. Menu [8].nm_Label   = GetVMMString (msgQuit);
  80. Menu [8].nm_CommKey = GetVMMString (msgQuitShort);
  81. Menu [9].nm_Label   = GetVMMString (msgEdit);
  82. Menu [10].nm_Label   = GetVMMString (msgDefaults);
  83. Menu [10].nm_CommKey = GetVMMString (msgDefaultsShort);
  84. Menu [11].nm_Label   = GetVMMString (msgLastSaved);
  85. Menu [11].nm_CommKey = GetVMMString (msgLastSavedShort);
  86. Menu [12].nm_Label   = GetVMMString (msgRestore);
  87. Menu [12].nm_CommKey = GetVMMString (msgRestoreShort);
  88.  
  89. Application = ApplicationObject, 
  90.   MUIA_Application_Author, AUTHOR,
  91.   MUIA_Application_Base, PROGNAME,
  92.   MUIA_Application_Title, PROGNAME,
  93.   MUIA_Application_Version, "$VER: 3.3",
  94.   MUIA_Application_Copyright, GetVMMString (msgCopyright),
  95.   MUIA_Application_Description, GetVMMString (msgVMMDescr),
  96.   MUIA_Application_UseCommodities, FALSE,
  97.   MUIA_Application_UseRexx, FALSE,
  98.   MUIA_Application_HelpFile, "HELP:english/VMM.guide",
  99.   SubWindow, WI_Window =
  100.     WindowObject,
  101.       MUIA_Window_Title, PROGNAME " " VER_STRING,
  102.       MUIA_Window_CloseGadget, FALSE,
  103.       MUIA_Window_Menustrip, MUI_MakeObject (MUIO_MenustripNM, Menu, 0),
  104.       MUIA_Window_ID, 1,
  105.       WindowContents, 
  106.         VGroup,
  107.           MUIA_HelpNode, "VMMPREFS",
  108.           Child, 
  109.             RegisterGroup (Pages),
  110.               Child, CreateTaskPage (),
  111.               Child, CreateMemoryPage (),
  112.               Child, CreateMiscPage (),
  113.             End,
  114.           Child,
  115.             HGroup,
  116.               MUIA_Group_SameSize, TRUE,
  117.               Child, BT_Save = MyButton (msgSave, msgSaveShort),
  118.               Child, HSpace (0),
  119.               Child, BT_Use = MyButton (msgUse, msgUseShort),
  120.               Child, HSpace (0),
  121.               Child, BT_Cancel = MyButton (msgCancel, msgCancelShort),
  122.             End,
  123.         End,
  124.     End,
  125.   SubWindow, WI_TaskSelect = CreateTaskSelectWindow (),
  126. End;
  127.  
  128. AttachID_BT (BT_Save, SAVE_ID);
  129. AttachID_BT (BT_Use, USE_ID);
  130. AttachID_BT (BT_Cancel, CANCEL_ID);
  131. AttachID_BT (PO_Disks, POP_ID);
  132. AttachID_BT (BT_AddProg, ADDPROG_ID);
  133. AttachID_BT (BT_AddDir, ADDDIR_ID);
  134. AttachID_BT (BT_Top, TOP_ID);
  135. AttachID_BT (BT_AddTask, ADDTASK_ID);
  136. AttachID_BT (BT_Up, UP_ID);
  137. AttachID_BT (BT_Add, ADD_ID);
  138. AttachID_BT (BT_Down, DOWN_ID);
  139. AttachID_BT (BT_Delete, DELETE_ID);
  140. AttachID_BT (BT_Bottom, BOTTOM_ID);
  141. AttachID_BT (BT_Sort, SORT_ID);
  142. AttachID_CY (CY_CodeOptions, CODE_PG_ID);
  143. AttachID_CY (CY_DataOptions, DATA_PG_ID);
  144. AttachID_ST (ST_MinPublic, MINPUBLIC_ID);
  145. AttachID_ST (ST_MinNonPublic, MINNONPUBLIC_ID);
  146. AttachID_ST (ST_CurrentTask, TASKNAME_ID);
  147.  
  148. AttachID_CY (CY_MemFlags, MEMFLAGS_ID);
  149.  
  150. DoMethod (WI_TaskSelect, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  151.           WI_Window, 
  152.           3, MUIM_Set, MUIA_Window_Sleep, FALSE);
  153.  
  154.  
  155. DoMethod (WI_Window, MUIM_Window_SetCycleChain, 
  156.           LV_TaskList, /* ST_CurrentTask, */
  157.           CY_CodeOptions, CY_DataOptions,
  158.           ST_MinPublic, ST_MinNonPublic, 
  159.  
  160.           CY_Policy, SL_MinMem, SL_MaxMem,
  161.           CY_MemFlags, SL_Buffer, SL_Prio,
  162.           CY_Device, ST_PartName, ST_FileName,
  163.           SL_FileSize,
  164.           CM_StatEnabled, CM_Zoomed, 
  165.           ST_UnZLeft, ST_UnZTop,
  166.           ST_ZLeft, ST_ZTop,
  167.           CM_CacheZ2RAM, CM_WBPatch, CM_MemTracking,
  168.           ST_MinVMAlloc,
  169.           ST_EnableHotkey, ST_DisableHotkey,
  170.  
  171.           BT_Save, BT_Use, BT_Cancel,
  172.           NULL);
  173.  
  174.  
  175. set (WI_Window, MUIA_Window_ActiveObject, LV_TaskList);
  176.  
  177. /*
  178. DoMethod (LV_TaskList, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
  179.           WI_Window, 3, MUIM_Set, MUIA_Window_ActiveObject, ST_CurrentTask);
  180. DoMethod (LV_TaskList, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
  181.           ST_CurrentTask, 3, MUIM_Set, MUIA_String_BufferPos, 0);
  182. */
  183.  
  184. return ((BOOL)(Application != NULL));
  185. }
  186.  
  187. /***********************************************************************/
  188.  
  189. void DisposeGUI (void)
  190.  
  191. {
  192. MUI_DisposeObject (Application);
  193. }
  194.  
  195. /***********************************************************************/
  196.  
  197. BOOL ValidSettings (void)
  198.  
  199. {
  200. ULONG PageDev;
  201. char *PartName,
  202.      *FileName;
  203.  
  204. get (CY_Device, MUIA_Cycle_Active, &PageDev);
  205. get (ST_PartName, MUIA_String_Contents, &PartName);
  206. get (ST_FileName, MUIA_String_Contents, &FileName);
  207.  
  208. if (((PageDev == PD_PART) && 
  209.     ((PartName == NULL) || (*PartName == 0)))
  210.                      ||
  211.     ((PageDev != PD_PART) && 
  212.     ((FileName == NULL) || (*FileName == 0))))
  213.   {
  214.   MUI_Request (Application, NULL, 0L, NULL, "*_OK", GetVMMString (msgNameMissing));
  215.   return (FALSE);
  216.   }
  217.  
  218. return (TRUE);
  219. }
  220.  
  221. /***********************************************************************/
  222.  
  223. int HandleMUIId (ULONG id)
  224.  
  225. {
  226. struct TaskEntry *te;
  227. LONG pos, val;
  228. char *name;
  229.  
  230. if (id >= FIRST_MENU_ID && id <= LAST_MENU_ID)
  231.   {
  232.   if (HandleMenuChoice (id))
  233.     return (Q_DONTQUIT);
  234.   else
  235.     return (Q_QUITGUI);
  236.   }
  237.  
  238. switch (id)
  239.   {
  240.   case MUIV_Application_ReturnID_Quit:
  241.        return (Q_QUITBOTH);
  242.  
  243.   case SAVE_ID:
  244.        if (!ValidSettings ())
  245.          return (Q_DONTQUIT);
  246.        if (!WriteConfigFile (CFG_NAME_SAVE))
  247.          printf ("Couldn't write envarc file\n");
  248.        if (!WriteConfigFile (CFG_NAME_USE))
  249.          printf ("Couldn't write env file\n");
  250.  
  251.        if (!VMM_RUNNING)
  252.          StartVMM ();
  253.        return (Q_QUITGUI);
  254.  
  255.   case USE_ID:
  256.        if (!ValidSettings ())
  257.          return (Q_DONTQUIT);
  258.        if (!WriteConfigFile (CFG_NAME_USE))
  259.          printf ("Couldn't write env file\n");
  260.  
  261.        if (!VMM_RUNNING)
  262.          StartVMM ();
  263.        return (Q_QUITGUI);
  264.  
  265.   case CANCEL_ID:
  266.        if (!VMM_RUNNING)
  267.          StartVMM ();
  268.        return (Q_QUITGUI);
  269.  
  270.   case POP_ID:
  271.        HandleDiskPopup ();
  272.        break;
  273.  
  274.   case ADD_ID:
  275.        AddNamed (GetVMMString (msgNew));
  276.        break;
  277.  
  278.   case ADDPROG_ID:
  279.        {
  280.        struct FileRequester *AddProgReq;
  281.  
  282.        if ((AddProgReq = MUI_AllocAslRequest (ASL_FileRequest, NULL)) == NULL)
  283.          {
  284.          DisplayBeep (NULL);
  285.          break;
  286.          }
  287.  
  288.        if (MUI_AslRequestTags (AddProgReq, ASLFR_Window, VMMWindow,
  289.                                ASLFR_SleepWindow, TRUE,
  290.                                ASLFR_TitleText, GetVMMString (msgSelectProg),
  291.                                ASLFR_RejectIcons, TRUE,
  292.                                ASLFR_DoSaveMode, FALSE,
  293.                                TAG_DONE, 0L))
  294.          {
  295.          AddNamed (AddProgReq->fr_File);
  296.          }
  297.  
  298.        MUI_FreeAslRequest (AddProgReq);
  299.        }
  300.        break;
  301.  
  302.   case ADDDIR_ID:
  303.        {
  304.        struct FileRequester *AddDirReq;
  305.        char directory [300];
  306.        BPTR DirLock;
  307.  
  308.        if ((AddDirReq = MUI_AllocAslRequest (ASL_FileRequest, NULL)) == NULL)
  309.          {
  310.          DisplayBeep (NULL);
  311.          break;
  312.          }
  313.  
  314.        if (MUI_AslRequestTags (AddDirReq, ASLFR_Window, VMMWindow,
  315.                                ASLFR_SleepWindow, TRUE,
  316.                                ASLFR_TitleText, GetVMMString (msgSelectDir),
  317.                                ASLFR_DrawersOnly, TRUE,
  318.                                ASLFR_DoSaveMode, FALSE,
  319.                                TAG_DONE, 0L))
  320.          {
  321.          strcpy (directory, AddDirReq->fr_Drawer);
  322.          if (index (directory, ':') == 0)
  323.            {
  324.            /* Obtain a fully qualified path */
  325.            DirLock = Lock (directory, ACCESS_READ);
  326.            if (!NameFromLock (DirLock, directory, 300))
  327.              strcpy (directory, AddDirReq->fr_Drawer);
  328.            UnLock (DirLock);
  329.            }
  330.          if (*(directory + strlen (directory) - 1) != ':')
  331.            strcat (directory, "/");
  332.          AddNamed (directory);
  333.          }
  334.  
  335.        MUI_FreeAslRequest (AddDirReq);
  336.        }
  337.        break;
  338.  
  339.   case ADDTASK_ID:
  340.        BuildTaskList ();
  341.        break;
  342.  
  343.   case DELETE_ID:
  344.        DoMethod (LV_TaskList, MUIM_List_GetEntry, 
  345.                  MUIV_List_GetEntry_Active, &te);
  346.        DoMethod (LV_TaskList, MUIM_List_Remove, MUIV_List_Remove_Active);
  347.        break;
  348.  
  349.   case TOP_ID:
  350.        DoMethod (LV_TaskList, MUIM_List_Move, MUIV_List_Move_Active, 1);
  351.        set (LV_TaskList, MUIA_List_Active, 1);
  352.        break;
  353.  
  354.   case UP_ID:
  355.        DoMethod (LV_TaskList, MUIM_List_Move, MUIV_List_Move_Active,
  356.                  MUIV_List_Move_Previous);
  357.        set (LV_TaskList, MUIA_List_Active, MUIV_List_Active_Up);
  358.        break;
  359.  
  360.   case DOWN_ID:
  361.        DoMethod (LV_TaskList, MUIM_List_Move, MUIV_List_Move_Active,
  362.                  MUIV_List_Move_Next);
  363.        set (LV_TaskList, MUIA_List_Active, MUIV_List_Active_Down);
  364.        break;
  365.  
  366.   case BOTTOM_ID:
  367.        DoMethod (LV_TaskList, MUIM_List_Move, MUIV_List_Move_Active, 
  368.                  MUIV_List_Move_Bottom);
  369.        set (LV_TaskList, MUIA_List_Active, MUIV_List_Active_Bottom);
  370.        break;
  371.  
  372.   case SORT_ID:
  373.        DoMethod (LV_TaskList, MUIM_List_Sort);
  374.        break;
  375.  
  376.   case CODE_PG_ID:
  377.        DoMethod (LV_TaskList, MUIM_List_GetEntry, 
  378.                  MUIV_List_GetEntry_Active, &te);
  379.        get (CY_CodeOptions, MUIA_Cycle_Active, &pos);
  380.        te->te_teif.CodePaging = pos;
  381.        DoMethod (LV_TaskList, MUIM_List_Redraw, MUIV_List_Redraw_Active);
  382.        break;
  383.  
  384.   case DATA_PG_ID:
  385.        DoMethod (LV_TaskList, MUIM_List_GetEntry, 
  386.                  MUIV_List_GetEntry_Active, &te);
  387.        get (CY_DataOptions, MUIA_Cycle_Active, &pos);
  388.        te->te_teif.DataPaging = pos;
  389.        DoMethod (LV_TaskList, MUIM_List_Redraw, MUIV_List_Redraw_Active);
  390.        break;
  391.  
  392.   case MINPUBLIC_ID:
  393.        DoMethod (LV_TaskList, MUIM_List_GetEntry, 
  394.                  MUIV_List_GetEntry_Active, &te);
  395.        get (ST_MinPublic, MUIA_String_Integer, &val);
  396.        te->te_teif.MinPublic = val;
  397.        break;
  398.  
  399.   case MINNONPUBLIC_ID:
  400.        DoMethod (LV_TaskList, MUIM_List_GetEntry, 
  401.                  MUIV_List_GetEntry_Active, &te);
  402.        get (ST_MinNonPublic, MUIA_String_Integer, &val);
  403.        te->te_teif.MinNonPublic = val;
  404.        break;
  405.  
  406.   case TASKNAME_ID:
  407.        DoMethod (LV_TaskList, MUIM_List_GetEntry, 
  408.                  MUIV_List_GetEntry_Active, &te);
  409.        get (ST_CurrentTask, MUIA_String_Contents, &name);
  410.        FreeMem (te->te_TaskName, (ULONG)te->te_teif.NameLen);
  411.        te->te_teif.NameLen = strlen (name) + 1;
  412.        if ((te->te_TaskName = AllocMem ((ULONG)te->te_teif.NameLen, MEMF_PUBLIC)) == NULL)
  413.          break;
  414.        strcpy (te->te_TaskName, name);
  415.        DoMethod (LV_TaskList, MUIM_List_Redraw, MUIV_List_Redraw_Active);
  416.        break;
  417.  
  418.   case MEMFLAGS_ID:
  419.        {
  420.        ULONG flags;
  421.  
  422.        get (CY_MemFlags, MUIA_Cycle_Active, &val);
  423.        switch (val)
  424.          {
  425.          case MF_FAST: flags = MEMF_FAST | MEMF_PUBLIC; break;
  426.          case MF_CHIP: flags = MEMF_CHIP | MEMF_PUBLIC; break;
  427.          case MF_ANY:  flags = MEMF_ANY | MEMF_PUBLIC;  break;
  428.          }
  429.  
  430.        val = MaxAvailMem (flags) / (100 * 1024);
  431.        set (SL_MinMem, MUIA_Slider_Max, val);
  432.        set (SL_MaxMem, MUIA_Slider_Max, val);
  433.  
  434.        /* Because of a bug in MUI, notifications for MUIA_Slider_Level
  435.         * are forgotten when, when Slider_Max is reduced below Slider_Level.
  436.         * They are done by hand here instead.
  437.         */
  438.  
  439.        get (SL_MinMem, MUIA_Slider_Level, &val);
  440.        DoMethod (TX_MinMem, MUIM_SetAsString, MUIA_Text_Contents, 
  441.                  "%ld00 KByte", val);
  442.  
  443.        get (SL_MaxMem, MUIA_Slider_Level, &val);
  444.        DoMethod (TX_MaxMem, MUIM_SetAsString, MUIA_Text_Contents, 
  445.                  "%ld00 KByte", val);
  446.  
  447.        }
  448.        break;
  449.   }
  450.  
  451. return (Q_DONTQUIT);
  452. }
  453.  
  454. /***********************************************************************/
  455.  
  456. int HandleGUI (void)
  457.  
  458. {
  459. int running_state = Q_DONTQUIT;
  460. ULONG MUISignals,
  461.       WaitMask,
  462.       ReceivedSignals;
  463. ULONG ReturnedId;
  464.  
  465. if (!CreateGUI ())
  466.   {
  467.   printf ("Could not create MUI application\n");
  468.   CloseLibrary (MUIMasterBase);
  469.   return (Q_QUITGUI);
  470.   }
  471.  
  472. if (!ReadConfigFileMUI (CfgName))
  473.   MenuDefault ();
  474.  
  475. ReadConfigFromVMM ();
  476.  
  477. set(WI_Window, MUIA_Window_Open, TRUE);
  478. get (WI_Window, MUIA_Window_Window, &VMMWindow);
  479.  
  480. WaitMask = SIGBREAKF_CTRL_C | (1L << ExtCxPort->ShowSignal);
  481. if (CxParams != NULL)
  482.   WaitMask |= (1L << ExtCxPort->CxPort.mp_SigBit);
  483.  
  484.  
  485. ReceivedSignals = MUISignals = 0; /* to enter the input method once */
  486.   
  487. while (running_state == Q_DONTQUIT)
  488.   {
  489.   if ((MUISignals & ReceivedSignals) || (MUISignals == 0L))
  490.     {
  491.     ReturnedId = DoMethod(Application, MUIM_Application_Input, &MUISignals);
  492.     running_state = HandleMUIId (ReturnedId);
  493.     }
  494.  
  495.   if (running_state == Q_DONTQUIT && MUISignals != 0L) 
  496.     {
  497.     ReceivedSignals = Wait(MUISignals | WaitMask);
  498.  
  499.     if ((CxParams != NULL) && 
  500.         (ReceivedSignals & (1L << ExtCxPort->CxPort.mp_SigBit)))
  501.       {
  502.       int TermVMM;
  503.  
  504. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  505.  
  506.       TermVMM = HandleCxMsg ();
  507.       /* store the quit status which is 'stronger' */
  508.       running_state = MAX (TermVMM, running_state);      
  509.       }
  510.  
  511.     if (ReceivedSignals & (1L << ExtCxPort->ShowSignal))
  512.       set (Application, MUIA_Application_Iconified, FALSE);
  513.  
  514.     if (ReceivedSignals & SIGBREAKF_CTRL_C)
  515.       running_state = Q_QUITGUI;
  516.     }
  517.   }
  518.  
  519. DisposeGUI ();
  520. return (running_state);
  521. }
  522.